<?php
$periodM = ($periodM)?$periodM:array();
$semaine = ($semaine)?$semaine:array();
$thismonthnum = date('n');
array_push($periodM, $thismonthnum);
?>
<link href="<?php echo $this->basePath() . '/css/operationtest/multi-select.css'; ?>" media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript">
    $(document).ready(function() {
        $('.selectable').multiSelect({
            selectableHeader: "<div class='custom-header'><b>Périmètres</b><a onclick=\"multiSelectAll('select_all')\" class='ms-all'>Tout</a></div>",
            selectionHeader: "<div class='custom-header'><b>Périmètres choisis</b><a onclick=\"multiSelectAll('deselect_all')\" class='ms-all'>Aucun</a></div>",
            selectableFooter: "<div class='custom-footer'><input type='text' id='all-search' class='search-input' autocomplete='off' placeholder='Rechercher'></div>",
            selectionFooter: "<div class='custom-footer'><input type='text' id='my-search' class='search-input' autocomplete='off' placeholder='Rechercher'></div>"
        });
        
        $('#all-search').bind('keydown keypress keyup change', function(e) {
            if (e.which == 13 || e.keyCode == 13) {
                return false;
            } else {
                var search = this.value;
                var $li = $(".ms-selectable .ms-elem-selectable:not(.ms-selected)").hide();
                $li.filter(function() {
                    return $(this).text().toLowerCase().indexOf(search.toLowerCase()) >= 0;
                }).show();
            }
        });
        
        $('#my-search').bind('keydown keypress keyup change', function(e) {
            if (e.which == 13 || e.keyCode == 13) {
                return false;
            } else {
                var search = this.value;
                var $li = $(".ms-selection .ms-elem-selection.ms-selected").hide();
                $li.filter(function() {
                    return $(this).text().toLowerCase().indexOf(search.toLowerCase()) >= 0;
                }).show();
            }
        });
    });
</script>
<div class="content-head">
    <h3>Écran de sélection du périmètre</h3>
</div>
<div class="content-body">
    <form id="op-form" action="<?php //echo $this->url('operationtest/default', array('controller'=>'tableaudebord')) ?>" method="post">
    <div class="periodeBox">
        <table width="100%">
            <tr>
                <td class="tdLeft">Période</td>
                <td class="tdRight">
                    <table class="tRight">
                        <tr>
                            <?php for($y=date('Y');$y>2011;$y--): 
                            if($periodY) {
                                if(in_array($y, $periodY)){
                                    $checked = 'checked="checked"';
                                } else {
                                    $checked = '';
                                }
                            } else {
                                $checked = ($y==date('Y'))?'checked="checked"':'';   
                            }
                            ?>
                            <td><label>
                                <input type="checkbox" name="periodY[]" value="<?php echo $y; ?>" class="styled" <?php echo $checked; ?> /> <?php echo $y; ?>
                            </label></td>
                            <?php endfor; ?>
                        </tr>
                        <tr>
                            <td><label><input type="checkbox" name="periodM[]" value="1" class="styled" <?php echo (in_array(1, $periodM))?'checked="checked"':''; ?> /> Jan</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="2" class="styled" <?php echo (in_array(2, $periodM))?'checked="checked"':''; ?> /> Fév</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="3" class="styled" <?php echo (in_array(3, $periodM))?'checked="checked"':''; ?> /> Mar</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="4" class="styled" <?php echo (in_array(4, $periodM))?'checked="checked"':''; ?> /> Avr</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="5" class="styled" <?php echo (in_array(5, $periodM))?'checked="checked"':''; ?> /> Mai</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="6" class="styled" <?php echo (in_array(6, $periodM))?'checked="checked"':''; ?> /> Juin</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="7" class="styled" <?php echo (in_array(7, $periodM))?'checked="checked"':''; ?> /> Juil</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="8" class="styled" <?php echo (in_array(8, $periodM))?'checked="checked"':''; ?> /> Août</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="9" class="styled" <?php echo (in_array(9, $periodM))?'checked="checked"':''; ?> /> Sept</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="10" class="styled" <?php echo (in_array(10, $periodM))?'checked="checked"':''; ?> /> Oct</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="11" class="styled" <?php echo (in_array(11, $periodM))?'checked="checked"':''; ?> /> Nov</label></td>
                            <td><label><input type="checkbox" name="periodM[]" value="12" class="styled" <?php echo (in_array(12, $periodM))?'checked="checked"':''; ?> /> Déc</label></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div class="semaineBox">
        <table width="100%">
            <tr>
                <td class="tdLeft">Semaine</td>
                <td class="tdRight">
                    <table class="tRight allrbq">                        
                        <tr>
                            <td><label><input type="checkbox" name="semaine[]" value="1" class="styled" id="l1" <?php echo (in_array(1, $semaine))?'checked="checked"':''; ?> /> Lun</label></td>
                            <td><label><input type="checkbox" name="semaine[]" value="2" class="styled" id="l2" <?php echo (in_array(2, $semaine))?'checked="checked"':''; ?> /> Mar</label></td>
                            <td><label><input type="checkbox" name="semaine[]" value="3" class="styled" id="l3" <?php echo (in_array(3, $semaine))?'checked="checked"':''; ?> /> Mer</label></td>
                            <td><label><input type="checkbox" name="semaine[]" value="4" class="styled" id="l4" <?php echo (in_array(4, $semaine))?'checked="checked"':''; ?> /> Jeu</label></td>
                            <td><label><input type="checkbox" name="semaine[]" value="5" class="styled" id="l5" <?php echo (in_array(5, $semaine))?'checked="checked"':''; ?> /> Ven</label></td>
                            <td><label><input type="checkbox" name="semaine[]" value="6" class="styled" id="l6" <?php echo (in_array(6, $semaine))?'checked="checked"':''; ?> /> Sam</label></td>
                            <td><label><input type="checkbox" name="semaine[]" value="0" class="styled" id="l7" <?php echo (in_array(0, $semaine))?'checked="checked"':''; ?> /> Dim</label></td>                            
                        </tr>
                        <tr>
                            <td colspan="7">ou saisir date spécifique <input type="text" name="specific_date" class="datepicker" /><input type="hidden" name="altDate" id="altDate" /></td>                            
                        </tr>
                    </table>
                </td>
                <td><label><input type="checkbox" name="all-semaine" class="styled" id="uncheckall" onclick="uncheckAll();" /> <i>Tout décocher</i></label></td>
            </tr>
        </table>
    </div>
    <div id="rubrique">
        <input type="radio" id="radio1" name="rubrique" value="1" checked="checked" /><label for="radio1">Tableau de bord</label>
        <input type="radio" id="radio2" name="rubrique" value="2" /><label for="radio2">Synthèse</label>
        <input type="radio" id="radio3" name="rubrique" value="3" /><label for="radio3">Pilotage</label>
    </div>
    <div class="operationtestBox">
        <div class="select-wrapper">
            <select multiple="multiple" id="selectable" class="selectable" name="selectable[]">
                <!-- Liste des marchés -->
                <?php foreach ($marches as $marche) : ?>
                <option value="M-<?php echo $marche->idMarche;?>"><?php echo ucwords(mb_strtolower($marche->libelle, 'UTF-8'));?></option>
                <?php endforeach; ?>

                <!-- Liste des boutiques -->
                <?php foreach ($stores as $store) : ?>
                <option value="<?php echo $store->idStore;?>"><?php echo ucwords(mb_strtolower($store->name, 'UTF-8'));?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <p style="margin:20px 0; text-align:center"><input class="button" type="button" name="valid" value="Valider" onclick="submitForm();" /></p>
    </div>
    </form>
    <script src="<?php echo $this->basePath() . '/js/operationtest/jquery.quicksearch.js'; ?>" type="text/javascript"></script>
    <script src="<?php echo $this->basePath() . '/js/operationtest/jquery.multi-select.js'; ?>" type="text/javascript"></script>
</div>